package com.code.qgjx.service.impl;

import com.code.qgjx.entity.ResignCommit;
import com.code.qgjx.mapper.ResignCommitMapper;
import com.code.qgjx.service.ResignCommitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;

@Service
public class ResignCommitServiceImpl implements ResignCommitService {

    @Autowired
    private ResignCommitMapper resignCommitMapper;

    @Override
    public boolean createResignCommit(ResignCommit resignCommit) {
        // 检查是否已存在未处理的申请
        ResignCommit existingRequest = resignCommitMapper.checkExistingRequest(
            resignCommit.getUserId(), resignCommit.getJobPositionId());
        if (existingRequest != null) {
            throw new RuntimeException("已存在未处理的辞职申请");
        }
        return resignCommitMapper.insert(resignCommit) > 0;
    }

    @Override
    public boolean updateResignCommit(ResignCommit resignCommit) {
        return resignCommitMapper.update(resignCommit) > 0;
    }

    @Override
    public ResignCommit getResignCommit(Long id) {
        return resignCommitMapper.selectById(id);
    }

    @Override
    public List<Map> getResignCommitsByUserId(Long userId, int sta, int offset, int limit) {
        return resignCommitMapper.selectByUserId(userId,sta, offset, limit);
    }

    @Override
    public List<ResignCommit> getResignCommitsByTeacherId(Long teacherId, int offset, int limit) {
        return resignCommitMapper.selectByTeacherId(teacherId, offset, limit);
    }

    @Override
    public int getResignCommitCountByUserId(Long userId) {
        return resignCommitMapper.selectCountByUserId(userId);
    }

    @Override
    public int getResignCommitCountByTeacherId(Long teacherId) {
        return resignCommitMapper.selectCountByTeacherId(teacherId);
    }

    @Override
    public boolean deleteResignCommit(Long id) {
        return resignCommitMapper.deleteById(id) > 0;
    }
} 